<?php

namespace app\model\questionnaire;

use app\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
use app\model\UserModel;

/**
 * 问卷-题库
 */
class QuestionnaireTopicModel extends BaseModel
{
    protected $name = 'questionnaire_topic';

    /**
     * 发布人
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(UserModel::class,'uid')->bind([
            'user_name' => 'name'
        ]);
    }

    /**
     * 标签
     * @return HasMany
     */
    public function label(): HasMany
    {
        return $this->hasMany(QuestionnaireTopicLabelModel::class, 'topic_id');
    }

    /**
     * 图片
     * @return HasMany
     */
    public function img(): HasMany
    {
        return $this->hasMany(QuestionnaireTopicImgModel::class, 'topic_id');
    }

    /**
     * 答案
     * @return HasMany
     */
    public function answer(): HasMany
    {
        return $this->hasMany(QuestionnaireTopicAnswerModel::class, 'topic_id');
    }

}